﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace LogInModule.Views.Helpers
{
    public static class AnimationFactory
    {
        public static DoubleAnimation CreateScaleXAnimation(ScaleTransform scale, double to, double seconds)
        {
            var scallingXAnimation = new DoubleAnimation
            {
                To = to,
                Duration = new Duration(TimeSpan.FromSeconds(seconds)),
            };
            Storyboard.SetTarget(scallingXAnimation, scale);
            Storyboard.SetTargetProperty(scallingXAnimation, new PropertyPath("ScaleX"));

            return scallingXAnimation;
        }

        public static DoubleAnimation CreateScaleYAnimation(ScaleTransform scale, double to, double seconds)
        {
            var scallingYAnimation = new DoubleAnimation
            {
                To = to,
                Duration = new Duration(TimeSpan.FromSeconds(seconds)),
            };
            Storyboard.SetTarget(scallingYAnimation, scale);
            Storyboard.SetTargetProperty(scallingYAnimation, new PropertyPath("ScaleY"));

            return scallingYAnimation;
        }

        public static DoubleAnimation CreateTranslateXAnimation(TranslateTransform translate, double to, double seconds)
        {
            var translateXAnimation = new DoubleAnimation
            {
                To = to,
                Duration = new Duration(TimeSpan.FromSeconds(seconds)),
            };
            Storyboard.SetTarget(translateXAnimation, translate);
            Storyboard.SetTargetProperty(translateXAnimation, new PropertyPath("X"));

            return translateXAnimation;
        }

        public static DoubleAnimation CreateTranslateYAnimation(TranslateTransform translate, double to, double seconds)
        {
            var translateYAnimation = new DoubleAnimation
            {
                To = to,
                Duration = new Duration(TimeSpan.FromSeconds(seconds)),
            };
            Storyboard.SetTarget(translateYAnimation, translate);
            Storyboard.SetTargetProperty(translateYAnimation, new PropertyPath("Y"));

            return translateYAnimation;
        }

        public static DoubleAnimation CreateOpacityAnimation(UIElement element, double to, double beginTime, double duration)
        {
            var opacityAnimation = new DoubleAnimation
            {
                BeginTime = TimeSpan.FromSeconds(beginTime),
                Duration = new Duration(TimeSpan.FromSeconds(duration)),
                To = to,
            };

            Storyboard.SetTarget(opacityAnimation, element);
            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
            return opacityAnimation;
        }

        public static Timeline CreateRotationAnimation(RotateTransform rotate, double angle, double seconds)
        {
            var rotateAnimation = new DoubleAnimation
            {
                To = angle,
                Duration = new Duration(TimeSpan.FromSeconds(seconds)),
            };
            Storyboard.SetTarget(rotateAnimation, rotate);
            Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath("Angle"));
            return rotateAnimation;
        }

        public static DoubleAnimation CreateProjectionXAnimation(PlaneProjection projection, double to, double seconds)
        {
            return CreateProjectionAnimation(projection, to, seconds, "RotationX");
        }

        public static DoubleAnimation CreateProjectionYAnimation(PlaneProjection projection, double to, double seconds)
        {
            return CreateProjectionAnimation(projection, to, seconds, "RotationY");
        }

        public static DoubleAnimation CreateProjectionZAnimation(PlaneProjection projection, double to, double seconds)
        {
            return CreateProjectionAnimation(projection, to, seconds, "RotationZ");
        }

        private static DoubleAnimation CreateProjectionAnimation(PlaneProjection projection, double to, double seconds,
                                                          string projectionRotation)
        {
            var projectionAnimation = new DoubleAnimation
            {
                To = to,
                Duration = new Duration(TimeSpan.FromSeconds(seconds)),
            };
            Storyboard.SetTarget(projectionAnimation, projection);
            Storyboard.SetTargetProperty(projectionAnimation, new PropertyPath(projectionRotation));

            return projectionAnimation;
        }
    }
}
